//
//  MovieDetailViewController.m
//  UI_豆瓣
//
//  Created by dllo on 15/10/30.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "MovieDetailViewController.h"
#import "AppTools.h"
#import "UIImageView+WebCache.h"
#import "SDImageCache.h"
#import "MovieDetaView.h"
#import "Movie.h"
#import "MBProgressHUD.h"
#import "LoginViewController.h"
@interface MovieDetailViewController ()

@property (nonatomic, retain)MovieDetaView *detaV;
@property (nonatomic, retain) MBProgressHUD *hub;

@end

@implementation MovieDetailViewController

- (void)dealloc
{
    [_hub release];
    [_mov release];
    [_detaV release];
    [_movieID release];
    [super dealloc];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
//    CGFloat scrollHight = 0.0;
    scrollView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:scrollView];
    [scrollView release];
    
    
    self.detaV = [[MovieDetaView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    self.detaV.backgroundColor = [UIColor whiteColor];
    [scrollView addSubview:self.detaV];
    [_detaV release];

    
    
    
    //接收数据  请求数据
    NSString *urlStr = [NSString stringWithFormat:@"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/searchmovie.php?movieId=%@",self.movieID];
    
    //让菊花旋转起来
    self.hub = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [self.hub show:YES];
    self.hub.labelText = @"玩命加载ing......";
    [self.view addSubview:self.hub];

    
    [AppTools getDataWithUrlStr:urlStr andBlock:^(id result) {
        
        NSString *Code = [result objectForKey:@"error_code"];
        //        NSString *reason = [result objectForKey:@"reason"];
        NSMutableDictionary *dic = [result objectForKey:@"result"];
        
        
        //初始化
        self.mov = [[Movie alloc]init];
        //赋值
        [self.mov setValuesForKeysWithDictionary:dic];
        //        NSLog(@"11111%@",self.mov.title);
        
        self.navigationItem.title = self.mov.title;
        NSString *str1 = self.mov.rating;
        self.detaV.rating.text = [NSString stringWithFormat:@"评分: %@",str1];
        NSString *str2 = self.mov.rating_count;
        self.detaV.ratingCount.text = [NSString stringWithFormat:@"(%@评论)",str2];
        self.detaV.date.text = self.mov.release_date;
        self.detaV.runtime.text = self.mov.runtime;
        self.detaV.genres.text = self.mov.genres;
        self.detaV.country.text = self.mov.country;
        self.detaV.actorsContent.text = self.mov.actors;
        self.detaV.plotSimple.text = self.mov.plot_simple;
        [self.detaV.plotSimple sizeToFit];
        [self.detaV.actorsContent sizeToFit];
        //        NSLog(@"______%@",self.mov.rating);
        
        
        CGFloat scrollHight = self.detaV.plotSimple.frame.origin.y + self.detaV.plotSimple.frame.size.height + 64;
        [scrollView setContentSize:CGSizeMake(375, scrollHight)];
        
        NSURL *url = [NSURL URLWithString:[dic objectForKey:@"poster"]];
        [self.detaV.headImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"Movie111.png"]];
        
        self.detaV.backImageView.image = [UIImage imageNamed:@"2222.jpg"];
        self.detaV.backImageView.frame = CGRectMake(0, 0, 375, scrollHight);
        self.detaV.backImageView.alpha = 0.3;
        
        //让菊花停止
        [self.hub hide:YES];

        
    } error:^(NSError *error) {
        //让菊花停止
        [self.hub hide:YES];

    }];
    
    
    
    
    
    //设置左边按钮
    UIImage *leftImage = [UIImage imageNamed:@"btn_nav_back@2x.png"];
    //取消渲染
    leftImage  = [leftImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:leftImage style:UIBarButtonItemStyleDone target:self action:@selector(liftButton:)];
    
    //设置右边按钮
    UIImage *rightImage = [UIImage imageNamed:@"btn_nav_share@2x.png"];
    //取消渲染
    rightImage = [rightImage imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:rightImage style:UIBarButtonItemStyleDone target:self action:@selector(rightButton:)];
    
    
}

#pragma mark -- 右边按钮方法
-(void)rightButton:(UIButton *)button
{

    LoginViewController *loginVC = [[LoginViewController alloc]init];
    UINavigationController *logNaVC = [[UINavigationController alloc]initWithRootViewController:loginVC];
    
    [self presentViewController:logNaVC animated:YES completion:^{
        
        
    }];
    
}

//左边按钮
-(void)liftButton:(UIButton *)button
{
    [self.navigationController popViewControllerAnimated:YES];
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
